//
//  LZManagePicturePresenter.m
//  laziz_Merchant
//
//  Created by XMac on 17/3/10.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZManagePicturePresenter.h"
#import "NSString+Additions.h"
#import "NetworkServiceManager.h"

extern NSString *merchant;


static NSString *const kMainPhoto = @"/merchant/listMerchantHeadPhoto"; //餐厅头图列表

static NSString *const kRejectPictureList = @"/photo/listDeletePhoto"; //被驳回的照片列表

static NSString *const kPictureNum = @"/photo/getPhotoNum"; //商户上传的照片数量
static NSString *const kPictureList = @"/photo/list"; //照片列表
static NSString *const kPictureAdd = @"/photo/add"; //添加照片
static NSString *const kPictureDelete = @"/photo/delete"; //删除照片

@implementation LZManagePicturePresenter


-(void)getMainPhotoPictureWithSellid:(NSString *)sellID Success:(PresenterCommonSuccess)successBlokc Failure:(PresenterCommonFail)failureBlock{
    NSString *urlStr = COMBINATION(merchant,kMainPhoto);
    
    NSDictionary *dic = @{@"sellerId":sellID};
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        
        if ([LZBasePresenter isRequestStatusCodeCorrect:resultData fail:failureBlock]) {
            SAFE_BLOCK_INVOKE(successBlokc, resultData[@"data"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        SAFE_BLOCK_INVOKE(failureBlock, error.localizedDescription);
    }];
}




-(void)getPictureNumWithSellId:(NSString *)sellID Success:(PresenterCommonSuccess)successBlokc Failure:(PresenterCommonFail)failureBlock{
    NSString *urlStr = COMBINATION(merchant,kPictureNum);
    
    NSDictionary *dic = @{@"sellerId":sellID};

    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        
        if ([LZBasePresenter isRequestStatusCodeCorrect:resultData fail:failureBlock]) {
            SAFE_BLOCK_INVOKE(successBlokc, resultData[@"data"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        SAFE_BLOCK_INVOKE(failureBlock, error.localizedDescription);
    }];

}


-(void)getPictureListWithSellId:(NSString *)sellID andPhotoType:(NSString *)photoType Success:(PresenterCommonSuccess)successBlokc Failure:(PresenterCommonFail)failureBlock{
    
    NSString *urlStr = COMBINATION(merchant,kPictureList);
    
    NSDictionary *dic = @{@"sellerId":sellID,@"photoType":photoType};
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        
        if ([LZBasePresenter isRequestStatusCodeCorrect:resultData fail:failureBlock]) {
            SAFE_BLOCK_INVOKE(successBlokc, resultData[@"data"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        SAFE_BLOCK_INVOKE(failureBlock, error.localizedDescription);
    }];
}



-(void)addPictureWithSellId:(NSString *)sellID andPhotoType:(NSString *)photoType andPhotoUrls:(NSArray *)photoUrls andToken:(NSString *)token Success:(PresenterCommonSuccess)successBlokc Failure:(PresenterCommonFail)failureBlock{
    NSString *urlStr = COMBINATION(merchant,kPictureAdd);
    NSDictionary *dic = @{
                          @"sellerId":sellID,
                          @"photoType":photoType,
                          @"photoUrls":photoUrls,
                          @"token":token
                          };
    
    
    [[NetworkServiceManager manager]executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        if ([LZBasePresenter isRequestStatusCodeCorrect:resultData fail:failureBlock]) {
            SAFE_BLOCK_INVOKE(successBlokc, resultData[@"data"]);
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        SAFE_BLOCK_INVOKE(failureBlock, error.localizedDescription);
    }];
}


-(void)deletePictureWithSellId:(NSString *)sellID andPhotoIds:(NSArray *)photoIds andToken:(NSString *)token Success:(PresenterCommonSuccess)successBlokc Failure:(PresenterCommonFail)failureBlock{
    NSString *urlStr = COMBINATION(merchant,kPictureDelete);
    
    NSDictionary *dic = @{
                          @"sellerId":sellID,
                          @"token":token,
                          @"photoIds":photoIds
                          };
    
    [[NetworkServiceManager manager]executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        if ([LZBasePresenter isRequestStatusCodeCorrect:resultData fail:failureBlock]) {
            SAFE_BLOCK_INVOKE(successBlokc, resultData[@"data"]);
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        SAFE_BLOCK_INVOKE(failureBlock, error.localizedDescription);
    }];
}

-(void)getPictureRejectListWithDelBatch:(NSString *)delBatch Success:(PresenterCommonSuccess)successBlokc Failure:(PresenterCommonFail)failureBlock{
    NSString *urlStr = COMBINATION(merchant,kRejectPictureList);
    
    NSDictionary *dic = @{@"delBatch":delBatch};
    
    [[NetworkServiceManager manager] executePostTask:urlStr parameters:dic success:^(NSURLSessionDataTask *task, id resultData) {
        
        if ([LZBasePresenter isRequestStatusCodeCorrect:resultData fail:failureBlock]) {
            SAFE_BLOCK_INVOKE(successBlokc, resultData[@"data"]);
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        SAFE_BLOCK_INVOKE(failureBlock, error.localizedDescription);
    }];
}



@end
